# -*- coding:utf-8 -*-
"""
this file is for process the xiami info
"""
import urllib
import simplejson
import re

def getLanguageOfAlbumId(aid):
    """
    album url : http://www.xiami.com/album/{{id}}
    """
    theurl = "http://www.xiami.com/album/"+str(aid)
    thestr = urllib.urlopen(theurl).read()

    langregex = "<td(\s|\S)*?语种(\s|\S)*?</tr>"
    langm = re.search(langregex,thestr)
    if langm:
        tmpstr = thestr[langm.start():langm.end()]
        ei = tmpstr.rindex("</td>")
        bi = tmpstr.rindex(">",0,ei)
        #print len(tmpstr)
        #print ei
        #print bi
        return tmpstr[bi+1:ei]
    else:
        print "not found"

if __name__ == "__main__":
    #getLanguageOfAlbumId(446078)
    #getLanguageOfAlbumId(6017)
